import axios from "axios";
import {getToken} from "@/utils/auth";
import {EventBus} from '@/main';

let ws;
let canvas;
let context;
let canvasSecond;
let contextSecond;
let canvasX;
let canvasY;
let canvasLastX;
let canvasLastY;
let isDragging = false;
let canvasX_manual = 0;
let canvasY_manual = 0;
let recX_manual = 0;
let recY_manual = 0;
let recW_manual = 0;
let recH_manual = 0;
let rec_ww = 0;
let rec_hh = 0;
let CutType = 0;
let imgOrignalW = 0;
let imgOrignalH = 0;
let rorateAngleType = 0;
let cutXCaibian = 0;
let cutYCaibian = 0;
let isDrawMove = false;

let canvasLastX2;
let canvasLastY2;
let isDragging2 = false;
let canvasX_manual2 = 0;
let canvasY_manual2 = 0;
let recX_manual2 = 0;
let recY_manual2 = 0;
let recW_manual2 = 0;
let recH_manual2 = 0;
let rec_ww2 = 0;
let rec_hh2 = 0;
let imgOrignalW2 = 0;
let imgOrignalH2 = 0;
let isDrawMove2 = false;
let cutXCaibian2 = 0;
let cutYCaibian2 = 0;

let faceZuobiao = new Array()
let faceZuobiaoSecond = new Array()
let faceNum = 0;
let faceNumSecond = 0;
let isFaceOpen = false;
let isFaceOpenSecond = false;

let setCusCut1 = false;
let cusCutX1 = 0;
let cusCutY1 = 0;
let cusCutW1 = 0;
let cusCutH1 = 0;

let setCusCut2 = false;
let cusCutX2 = 0;
let cusCutY2 = 0;
let cusCutW2 = 0;
let cusCutH2 = 0;
let isSecondDev = false; //是否有两个canvas显示视频

let camidMain = 0;    //主头ID
let camidSub = 0;     //副头ID

let imageData;

let personFileId;


let cameraResolution = {width: 1920, height: 1080}

export function WsInit(orignalCanvasW, orignalCanvasH, orignalCanvasW2, orignalCanvasH2, enableCanvas, canvas) {
    WsInit_ip(orignalCanvasW, orignalCanvasH, orignalCanvasW2, orignalCanvasH2, enableCanvas, "localhost", canvas);
}

export function WsInit_ip(orignalCanvasW, orignalCanvasH, orignalCanvasW2, orignalCanvasH2, enableCanvas, ip, canvas1) {
    if (enableCanvas) {
        canvas = canvas1;
        context = canvas.getContext("2d");
        if (isSecondDev) {
            canvasSecond = document.getElementById("cameraCanvasSecond");
            contextSecond = canvasSecond.getContext("2d");
            canvasSecond.onmousedown = canvasClick2;
            canvasSecond.onmouseup = stopDragging2;
            canvasSecond.onmouseout = stopDragging2;
            canvasSecond.onmousemove = canvasMove2;

            canvasSecond.setAttribute('width', canvasSecond.parentElement.offsetWidth);
            canvasSecond.setAttribute('height', canvasSecond.parentElement.offsetHeight);

            orignalCanvasW2 = canvasSecond.parentElement.offsetWidth;
            orignalCanvasH2 = canvasSecond.parentElement.offsetHeight;
        }
        canvas.onmousedown = canvasClick;
        canvas.onmouseup = stopDragging;
        canvas.onmouseout = stopDragging;
        canvas.onmousemove = canvasMove;
        canvasX = 0;
        canvasY = 0;
        canvasLastX = 0;
        canvasLastY = 0;
        const offsetHeight = canvas.parentElement.offsetHeight;
        canvas.setAttribute('height', offsetHeight);
        canvas.setAttribute('width', offsetHeight * (210 / 297));


        orignalCanvasW = canvas.offsetWidth;
        orignalCanvasH = canvas.offsetHeight;
    }

    ws = new WebSocket("ws://" + ip + ":9002");
    ws.binaryType = "arraybuffer";
    ws.onmessage = function (event) {
        if (typeof (event.data) == "string") {
            console.log("ws.GetPicBase64", event.data)
            if (event.data.indexOf("GetPicBase64:") >= 0) {
                EventBus.$emit('camera.getPicBase64', event.data.slice(13))
                //imageData = InfoTextCallback(5, strTemp);
            } else if (event.data.indexOf("GetPic2Base64:") >= 0) {
                let strTemp = event.data.substr(14);
                imageData = InfoTextCallback(21, strTemp);
            }
            return;
        }

        let aDataArray = new Uint8Array(event.data);
        if (aDataArray.length > 0) {
            if (aDataArray[1] !== 5) {
                //console.log(aDataArray)
            }
            if (aDataArray[0] == 0xef && aDataArray[1] == 0x01) {
                // getDeviceName(aDataArray[3]);
                // getResolution(aDataArray,5);
                getUsbCamareMessage(aDataArray, 5)
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x17) {
                let camNum = aDataArray[3];
                //GetDevCount(camNum);
                InfoTextCallback(26, camNum);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x19) {
                EventBus.$emit('camera.resolution', aDataArray, 5)
                getResolution(aDataArray, 5);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x23) {
                //getResolution(aDataArray,4);
                let type = aDataArray[3];
                let len = aDataArray[4];
                let data = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    data[i] = aDataArray[5 + i];
                }
                let str = byteToString(data)
                let text = decodeURIComponent(str);
                InfoTextCallback(type, text);

            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x05) {
                let ww = aDataArray[3] * 256 + aDataArray[4];
                let hh = aDataArray[5] * 256 + aDataArray[6];
                context.clearRect(0, 0, canvas.width, canvas.height);
                //sendMsgRefreshCam();
                let imgData = context.createImageData(ww, hh);
                let dataNum = 0;
                for (let i = 0; i < imgData.data.length; i += 4) {
                    imgData.data[i + 0] = aDataArray[dataNum];
                    imgData.data[i + 1] = aDataArray[dataNum + 1];
                    imgData.data[i + 2] = aDataArray[dataNum + 2];
                    imgData.data[i + 3] = 255;
                    dataNum = dataNum + 3;
                }
                sendMsgRefreshCam();

                if (CutType == 2) {
                    rec_ww = ww;
                    rec_hh = hh;
                    context.putImageData(imgData, canvas.width / 2 - ww / 2, canvas.height / 2 - hh / 2);

                    SetCusCutFirst();
                    refreshRect();
                } else context.putImageData(imgData, canvas.width / 2 - ww / 2 + canvasX, canvas.height / 2 - hh / 2 + canvasY);


                context.beginPath();
                context.strokeStyle = "rgb(0,255,0)";
                context.lineWidth = 2;
                GetFaceZuobiao(canvas.width / 2 - ww / 2 + canvasX, canvas.height / 2 - hh / 2 + canvasY);


            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x0c) {
                let ww = aDataArray[3] * 256 + aDataArray[4];
                let hh = aDataArray[5] * 256 + aDataArray[6];
                context.clearRect(0, 0, canvas.width, canvas.height);
                //sendMsgRefreshCam();
                let imgData = context.createImageData(ww, hh);
                let dataNum = 0;
                for (let i = 0; i < imgData.data.length; i += 4) {
                    imgData.data[i + 0] = aDataArray[dataNum];
                    imgData.data[i + 1] = aDataArray[dataNum + 1];
                    imgData.data[i + 2] = aDataArray[dataNum + 2];
                    imgData.data[i + 3] = 255;
                    dataNum = dataNum + 3;
                }
                sendMsgRefreshCam();
                let Xdis = canvas.width / 2 - ww / 2 + canvasX;
                let Ydis = canvas.height / 2 - hh / 2 + canvasY;
                context.putImageData(imgData, Xdis, Ydis);

                let lenJiubian = aDataArray[7];


                context.beginPath();
                context.strokeStyle = "rgb(0,255,0)";
                context.lineWidth = 2;

                for (let j = 0; j < lenJiubian; j++) {
                    for (let i = 0; i < 3; i++) {
                        let aa = 1;
                        if (aDataArray[8 + i * 6 + j * 24] == 1) {
                            aa = -1;
                        }
                        let bb = 1;
                        if (aDataArray[11 + i * 6 + j * 24] == 1) {
                            bb = -1;
                        }
                        let cc = 1;
                        if (aDataArray[14 + i * 6 + j * 24] == 1) {
                            cc = -1;
                        }
                        let dd = 1;
                        if (aDataArray[17 + i * 6 + j * 24] == 1) {
                            dd = -1;
                        }
                        context.moveTo(aDataArray[9 + i * 6 + j * 24] * 256 * aa + aDataArray[10 + i * 6 + j * 24] * aa + Xdis, aDataArray[12 + i * 6 + j * 24] * 256 * bb + aDataArray[13 + i * 6 + j * 24] * bb + Ydis);
                        context.lineTo(aDataArray[15 + i * 6 + j * 24] * 256 * cc + aDataArray[16 + i * 6 + j * 24] * cc + Xdis, aDataArray[18 + i * 6 + j * 24] * 256 * dd + aDataArray[19 + i * 6 + j * 24] * dd + Ydis);
                        context.stroke();
                    }
                    let ee = 1;
                    if (aDataArray[26 + j * 24] == 1) {
                        ee = -1;
                    }
                    let ff = 1;
                    if (aDataArray[8 + j * 24] == 1) {
                        ff = -1;
                    }
                    context.moveTo(aDataArray[27 + j * 24] * 256 + aDataArray[28 + j * 24] + Xdis, aDataArray[30 + j * 24] * 256 + aDataArray[31 + j * 24] + Ydis);
                    context.lineTo(aDataArray[9 + j * 24] * 256 + aDataArray[10 + j * 24] + Xdis, aDataArray[12 + j * 24] * 256 + aDataArray[13 + j * 24] + Ydis);
                    context.stroke();
                }
                GetFaceZuobiao(canvas.width / 2 - ww / 2 + canvasX, canvas.height / 2 - hh / 2 + canvasY);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x14) {
                let tmp = aDataArray[3];
                if (tmp == 0x46) {
                    isFaceOpen = true;
                } else if (tmp == 0x48) {
                    isFaceOpenSecond = true;
                } else if (tmp == 0x5e) {
                    isFaceOpen = true;
                    isFaceOpenSecond = true;
                } else if (tmp == 0x5f) {
                    isFaceOpen = true;
                } else if (tmp == 0x61) {
                    isFaceOpenSecond = true;
                }

                InfoCallback(tmp);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x26) {

                if (isSecondDev) {
                    let ww = aDataArray[3] * 256 + aDataArray[4];
                    let hh = aDataArray[5] * 256 + aDataArray[6];
                    contextSecond.clearRect(0, 0, canvasSecond.width, canvasSecond.height);

                    let imgData = contextSecond.createImageData(ww, hh);
                    let dataNum = 0;
                    for (let i = 0; i < imgData.data.length; i += 4) {
                        imgData.data[i + 0] = aDataArray[dataNum];
                        imgData.data[i + 1] = aDataArray[dataNum + 1];
                        imgData.data[i + 2] = aDataArray[dataNum + 2];
                        imgData.data[i + 3] = 255;
                        dataNum = dataNum + 3;

                    }
                    sendMsgRefreshCamSecond();


                    contextSecond.putImageData(imgData, canvasSecond.width / 2 - ww / 2, canvasSecond.height / 2 - hh / 2);
                    if (CutType == 2) {
                        rec_ww2 = ww;
                        rec_hh2 = hh;

                        SetCusCutSec();
                        refreshRect2();
                    }
                    GetFaceZuobiaoSecond(canvasSecond.width / 2 - ww / 2, canvasSecond.height / 2 - hh / 2)
                }
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x30) {
                let type1 = aDataArray[3];
                let ret = 1;
                if (type1 == 0) {
                    ret = -1;
                }
                let min = aDataArray[4] * ret;
                let type2 = aDataArray[5];
                ret = 1;
                if (type2 == 0) {
                    ret = -1;
                }
                let max = aDataArray[6] * ret;
                let text = "" + min + "*" + max;
                InfoTextCallback(23, text);
                // GetBrightnessRange_ws(min,max);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x32) {
                let type1 = aDataArray[3];
                let ret = 1;
                if (type1 == 0) {
                    ret = -1;
                }
                let min = aDataArray[4] * ret;

                let type2 = aDataArray[5];
                ret = 1;
                if (type2 == 0) {
                    ret = -1;
                }
                //let max = aDataArray[6]*ret;
                let max = aDataArray[6] * ret;
                let text = "" + min + "*" + max;
                InfoTextCallback(22, text);
                // GetExposureRange_ws(min,max);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x36) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(5, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x3b) {
                EventBus.$emit("camera.mainDevId", aDataArray[3])
                camidMain = aDataArray[3];
                // if(isSecondDev){
                camidSub = aDataArray[4];
                //}
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x3e) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                InfoTextCallback(19, text);

            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x43) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(21, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x4a) {
                rorateAngleType = aDataArray[3];
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x4c) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(25, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x5f) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(28, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x60) {
                faceNum = aDataArray[3];
                for (let j = 0; j < faceNum * 4; j++) {

                    let aa = 1;
                    if (aDataArray[4 + j * 6] == 1) {
                        aa = -1;
                    }

                    faceZuobiao[j * 2] = aDataArray[5 + j * 6] * 256 * aa + aDataArray[6 + j * 6] * aa;


                    let bb = 1;
                    if (aDataArray[7 + j * 6] == 1) {
                        bb = -1;
                    }
                    faceZuobiao[j * 2 + 1] = aDataArray[8 + j * 6] * 256 * bb + aDataArray[9 + j * 6] * bb;

                }


            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x62) {
                faceNumSecond = aDataArray[3];
                for (let j = 0; j < faceNumSecond * 4; j++) {

                    let aa = 1;
                    if (aDataArray[4 + j * 6] == 1) {
                        aa = -1;
                    }

                    faceZuobiaoSecond[j * 2] = aDataArray[5 + j * 6] * 256 * aa + aDataArray[6 + j * 6] * aa;


                    let bb = 1;
                    if (aDataArray[7 + j * 6] == 1) {
                        bb = -1;
                    }
                    faceZuobiaoSecond[j * 2 + 1] = aDataArray[8 + j * 6] * 256 * bb + aDataArray[9 + j * 6] * bb;

                }


            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x67) {
                let tmp = aDataArray[3];
                if (tmp == 0x00) {
                    faceNum = 0;
                } else if (tmp == 0x01) {
                    faceNumSecond = 0;
                }
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x71) {
                //getResolution(aDataArray,4);
                let type = aDataArray[3];
                let len = aDataArray[4] * 256 + aDataArray[5];
                let data = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    data[i] = aDataArray[6 + i];
                }
                let str = byteToString(data)
                let text = decodeURIComponent(str);
                InfoTextCallback(type, text);

            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x73) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(30, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x7e) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(33, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x84) {
                let len = aDataArray[3] * 65536 + aDataArray[4] * 256 + aDataArray[5];
                let baseDataArray = new Uint8Array(len);
                for (let i = 0; i < len; i++) {
                    baseDataArray[i] = aDataArray[6 + i];
                }
                let str = byteToString(baseDataArray);
                let text = decodeURIComponent(str);

                let last = text.substr(str.length - 2, 1);
                let lastSecond = text.substr(str.length - 3, 1);
                if (last == "=" && lastSecond != "=") {
                    text = text.substring(0, text.length - 1)
                    text = text + "=";
                }

                InfoTextCallback(36, text);
            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x80) {
                //getResolution(aDataArray,4);
                let len = aDataArray[3] * 256 + aDataArray[4];
                InfoTextCallback(34, len);

            } else if (aDataArray[0] == 0xef && aDataArray[1] == 0x92) {
                let len = aDataArray[3] * 256 + aDataArray[4];
                InfoTextCallback(37, len);

            }
        }

    };
    // ´ò¿ªWebSocket
    ws.onclose = function (event) {
        //WebSocket Status:: Socket Closed
        InfoCallback(0xa3);
        //alert("程序出现异常,请重新启动0x00");
    };
    // ´ò¿ªWebSocket
    ws.onopen = function (event) {
        if (enableCanvas) {
            sendSendStrBase64();
            sendMsgGetMainCameraID();
            sendMsgRefreshDev();
            initParameter(orignalCanvasW, orignalCanvasH, orignalCanvasW2, orignalCanvasH2);
        }

        InfoCallback(0x24);

    };
    ws.onerror = function (event) {
        //WebSocket Status:: Error was reported
        InfoCallback(0xa4);
        // alert("程序出现异常,请重新启动0x01");
    };
}

function initParameter(orignalCanvasW, orignalCanvasH, orignalCanvasW2, orignalCanvasH2) {
    sendMsgBestSize();
    sendMsgSetCutType(0);
    sendMsgSetFileType(0);
    sendMsgSetImageColorMode(0);
    sendMsgSetConntinousShotModel(0);
    sendMsgChangeOrientation(0);
    sendMsgSetCanvasOriginalSize(orignalCanvasW, orignalCanvasH);
    sendMsgSetCanvasSecondOriginalSize(orignalCanvasW2, orignalCanvasH2);

}

function canvasClick(e) {
    isDragging = true;
    if (!isDrawMove) {
        canvasLastX = 0;

        canvasLastY = 0;
        canvasX_manual = 0;
        canvasY_manual = 0;

        recX_manual = 0;
        recY_manual = 0;
        recW_manual = 0;
        recH_manual = 0;
    } else {

    }
}

function stopDragging() {
    isDragging = false;
    canvasLastX = 0;
    canvasLastY = 0;
    canvasX_manual = 0;
    canvasY_manual = 0;
    if (CutType == 2) {
        bpp = rec_ww / imgOrignalW;
        if (rorateAngleType == 1 || rorateAngleType == 3) {
            bpp = rec_ww / imgOrignalH;
        }
        cutXCaibian = Math.abs(recW_manual) / bpp;
        cutYCaibian = Math.abs(recH_manual) / bpp;
    }
}

function getTop(e) {
    let offset = e.offsetTop;
    if (e.offsetParent != null) offset += getTop(e.offsetParent);
    return offset;
}

//获取元素的横坐标
function getLeft(e) {
    let offset = e.offsetLeft;
    if (e.offsetParent != null) offset += getLeft(e.offsetParent);
    return offset;
}

function canvasMove(e) {
    // let mx = e.pageX - canvas.offsetLeft;
    // let my = e.pageY - canvas.offsetTop;

    let mx = e.pageX - getLeft(canvas);
    let my = e.pageY - getTop(canvas);
    if (CutType == 2) {
        let x1 = recX_manual;
        let x2 = recX_manual + recW_manual;
        if (x1 > x2) {
            x1 = x2;
            x2 = recX_manual;
        }

        let y1 = recY_manual;
        let y2 = recY_manual + recH_manual;
        if (y1 > y2) {
            y1 = y2;
            y2 = recY_manual;
        }

        if (x1 <= mx && mx <= x2 && y1 <= my && my <= y2) {
            isDrawMove = true;
            if (isDragging) {
                if (canvasLastX == 0 && canvasLastY == 0) {
                    canvasLastX = mx;
                    canvasLastY = my;

                } else {
                    recX_manual = recX_manual + (mx - canvasLastX);
                    recY_manual = recY_manual + (my - canvasLastY);
                    canvasLastX = mx;
                    canvasLastY = my;
                }

            }
            return;
        } else if (x1 - 30 <= mx && mx <= x2 + 30 && y1 - 30 <= my && my <= y2 + 30) {
            isDrawMove = true;
            if (isDragging) {
                if (canvasLastX == 0 && canvasLastY == 0) {

                    canvasLastX = mx;
                    canvasLastY = my;

                } else {

                    let tmpX2 = recX_manual + recW_manual;
                    if (Math.abs(recX_manual - mx) < Math.abs(tmpX2 - mx)) {
                        recX_manual = recX_manual + (mx - canvasLastX);
                        recW_manual = recW_manual - (mx - canvasLastX);
                    } else recW_manual = recW_manual + (mx - canvasLastX);

                    let tmpY2 = recY_manual + recH_manual;
                    if (Math.abs(recY_manual - my) < Math.abs(tmpY2 - my)) {
                        recY_manual = recY_manual + (my - canvasLastY);
                        recH_manual = recH_manual - (my - canvasLastY);
                    } else recH_manual = recH_manual + (my - canvasLastY);

                    canvasLastX = mx;
                    canvasLastY = my;
                }

                return;
            }
        } else isDrawMove = false;
    }

    if (isDragging == true) {
        if (CutType != 2) {
            if (canvasLastX == 0 && canvasLastY == 0) {
                canvasLastX = e.pageX - canvas.offsetLeft;
                canvasLastY = e.pageY - canvas.offsetTop;

            } else {

                canvasX = canvasX + (mx - canvasLastX);
                canvasY = canvasY + (my - canvasLastY);
                canvasLastX = mx;
                canvasLastY = my;
            }
        } else {


            if (canvasLastX == 0 && canvasLastY == 0) {

                canvasLastX = mx;
                canvasLastY = my;
                recX_manual = mx;
                recY_manual = my;
            } else {


                canvasX_manual = canvasX_manual + (mx - canvasLastX);
                canvasY_manual = canvasY_manual + (my - canvasLastY);
                canvasLastX = mx;
                canvasLastY = my;
                recW_manual = canvasX_manual;
                recH_manual = canvasY_manual;
            }

        }
    }
}

function canvasClick2(e) {
    isDragging2 = true;
    if (!isDrawMove2) {
        canvasLastX2 = 0;

        canvasLastY2 = 0;
        canvasX_manual2 = 0;
        canvasY_manual2 = 0;

        recX_manual2 = 0;
        recY_manual2 = 0;
        recW_manual2 = 0;
        recH_manual2 = 0;
    }
}

function stopDragging2() {
    isDragging2 = false;
    canvasLastX2 = 0;
    canvasLastY2 = 0;
    canvasX_manual2 = 0;
    canvasY_manual2 = 0;
    if (CutType == 2) {
        let bpp2 = rec_ww2 / imgOrignalW2;
        cutXCaibian2 = Math.abs(recW_manual2) / bpp2;
        cutYCaibian2 = Math.abs(recH_manual2) / bpp2;
    }
}

function canvasMove2(e) {
    let mx = e.pageX - canvasSecond.offsetLeft;
    let my = e.pageY - canvasSecond.offsetTop;
    if (CutType == 2) {
        let x1 = recX_manual2;
        let x2 = recX_manual2 + recW_manual2;
        if (x1 > x2) {
            x1 = x2;
            x2 = recX_manual2;
        }

        let y1 = recY_manual2;
        let y2 = recY_manual2 + recH_manual2;
        if (y1 > y2) {
            y1 = y2;
            y2 = recY_manual2;
        }

        if (x1 <= mx && mx <= x2 && y1 <= my && my <= y2) {
            isDrawMove2 = true;
            if (isDragging2) {
                if (canvasLastX2 == 0 && canvasLastY2 == 0) {
                    canvasLastX2 = mx;
                    canvasLastY2 = my;

                } else {
                    recX_manual2 = recX_manual2 + (mx - canvasLastX2);
                    recY_manual2 = recY_manual2 + (my - canvasLastY2);
                    canvasLastX2 = mx;
                    canvasLastY2 = my;
                }

            }
            return;

        } else if (x1 - 30 <= mx && mx <= x2 + 30 && y1 - 30 <= my && my <= y2 + 30) {
            isDrawMove2 = true;
            if (isDragging2) {
                if (canvasLastX2 == 0 && canvasLastY2 == 0) {

                    canvasLastX2 = mx;
                    canvasLastY2 = my;

                } else {

                    let tmpX2 = recX_manual2 + recW_manual2;
                    if (Math.abs(recX_manual2 - mx) < Math.abs(tmpX2 - mx)) {
                        recX_manual2 = recX_manual2 + (mx - canvasLastX2);
                        recW_manual2 = recW_manual2 - (mx - canvasLastX2);
                    } else recW_manual2 = recW_manual2 + (mx - canvasLastX2);

                    let tmpY2 = recY_manual2 + recH_manual2;
                    if (Math.abs(recY_manual2 - my) < Math.abs(tmpY2 - my)) {
                        recY_manual2 = recY_manual2 + (my - canvasLastY2);
                        recH_manual2 = recH_manual2 - (my - canvasLastY2);
                    } else recH_manual2 = recH_manual2 + (my - canvasLastY2);

                    canvasLastX2 = mx;
                    canvasLastY2 = my;
                }

                return;
            }
        } else isDrawMove2 = false;
    }

    if (isDragging2 == true) {
        if (CutType != 2) {

        } else {

            if (canvasLastX2 == 0 && canvasLastY2 == 0) {

                canvasLastX2 = mx;
                canvasLastY2 = my;
                recX_manual2 = mx;
                recY_manual2 = my;
            } else {

                canvasX_manual2 = canvasX_manual2 + (mx - canvasLastX2);
                canvasY_manual2 = canvasY_manual2 + (my - canvasLastY2);
                canvasLastX2 = mx;
                canvasLastY2 = my;
                recW_manual2 = canvasX_manual2;
                recH_manual2 = canvasY_manual2;
            }

        }
    }
}

function getResolution(arrayData, tmpNum) {
    console.log(arrayData)
    let type = arrayData[3]
    let len = arrayData[4];
    let data = new Int32Array(len * 2);
    let num = 0;
    for (let i = 0; i < len; i++) {
        data[num] = arrayData[tmpNum] * 256 + arrayData[tmpNum + 1];
        num++;
        data[num] = arrayData[tmpNum + 2] * 256 + arrayData[tmpNum + 3];
        num++;
        tmpNum += 4;
    }
    if (type == 0) {
        GetDeviceResolution(data);
    } else {
        if (isSecondDev) {
            GetDeviceResolutionSecond(data);
            LoadOver2();
        }
    }

}

function getUsbCamareMessage(arrayData, tmpNum) {
    let numCam = arrayData[3];
    let len = arrayData[4];
    let data = new Int32Array(len * 2);
    let num = 0;
    for (let i = 0; i < len; i++) {
        data[num] = arrayData[tmpNum] * 256 + arrayData[tmpNum + 1];
        num++;
        data[num] = arrayData[tmpNum + 2] * 256 + arrayData[tmpNum + 3];
        num++;
        tmpNum += 4;
    }
    GetDeviceResolution(data);
    LoadOver();

    let strUsbNamr = new Array()
    for (let i = 0; i < numCam; i++) {
        let tmpLen = arrayData[tmpNum];
        let tmpData = new Uint8Array(tmpLen);
        tmpNum++;
        for (let j = 0; j < tmpLen; j++) {
            tmpData[j] = arrayData[tmpNum];
            tmpNum++;
        }
        // let arr =       Utf8ToUnicode(tmpData)
        let str = byteToString(tmpData);
        let text = decodeURIComponent(str);
        strUsbNamr[i] = text;
    }
    GetDevName(numCam, strUsbNamr);


}


function sendMsgRefreshCam() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x04;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgStartVideo2(camId, width, height) {


    imgOrignalW2 = width;
    imgOrignalH2 = height;
    let aDataArray = new Uint8Array(8);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x25;
    aDataArray[2] = 0x05;
    aDataArray[3] = camId;
    aDataArray[4] = width / 256;
    aDataArray[5] = width % 256;
    aDataArray[6] = height / 256;
    aDataArray[7] = height % 256;
    ws.send(aDataArray.buffer);
}

function sendMsgStartVideo2YUV(camId, width, height) {


    imgOrignalW2 = width;
    imgOrignalH2 = height;
    let aDataArray = new Uint8Array(8);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x8b;
    aDataArray[2] = 0x05;
    aDataArray[3] = camId;
    aDataArray[4] = width / 256;
    aDataArray[5] = width % 256;
    aDataArray[6] = height / 256;
    aDataArray[7] = height % 256;
    ws.send(aDataArray.buffer);
}


function sendMsgRefreshCamSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x27;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetCanvasOriginalSize(ww, hh) {
    let aDataArray = new Uint8Array(7);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x15;
    aDataArray[2] = 0x04;
    aDataArray[3] = ww / 256;
    aDataArray[4] = ww % 256;
    aDataArray[5] = hh / 256;
    aDataArray[6] = hh % 256;
    ws.send(aDataArray.buffer);
}

function sendMsgSetCanvasSecondOriginalSize(ww, hh) {
    let aDataArray = new Uint8Array(7);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x37;
    aDataArray[2] = 0x04;
    aDataArray[3] = ww / 256;
    aDataArray[4] = ww % 256;
    aDataArray[5] = hh / 256;
    aDataArray[6] = hh % 256;
    ws.send(aDataArray.buffer);
}

export function sendMsgRefreshDev() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x00;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgStartVideo(camId, width, height) {

    if (width == 3672 || width == 4000 || width == 4208) {
        imgOrignalW = 3264;
        imgOrignalH = 2448;
    } else {
        imgOrignalW = width;
        imgOrignalH = height;
    }
    let aDataArray = new Uint8Array(8);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x02;
    aDataArray[2] = 0x05;
    aDataArray[3] = camId;
    aDataArray[4] = width / 256;
    aDataArray[5] = width % 256;
    aDataArray[6] = height / 256;
    aDataArray[7] = height % 256;
    EventBus.$emit("camera.setResolution", [width, height])
    ws.send(aDataArray.buffer);
}

function sendMsgStartVideoYUV(camId, width, height) {

    if (width == 3672 || width == 4000 || width == 4208) {
        imgOrignalW = 3264;
        imgOrignalH = 2448;

    } else {
        imgOrignalW = width;
        imgOrignalH = height;
    }
    let aDataArray = new Uint8Array(8);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x8a;
    aDataArray[2] = 0x05;
    aDataArray[3] = camId;
    aDataArray[4] = width / 256;
    aDataArray[5] = width % 256;
    aDataArray[6] = height / 256;
    aDataArray[7] = height % 256;
    ws.send(aDataArray.buffer);
}

function sendMsgChangeOrientation(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x06;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgSetImageColorMode(type) {
    let aDataArray2 = new Uint8Array(4);
    aDataArray2[0] = 0xef;
    aDataArray2[1] = 0x07;
    aDataArray2[2] = 0x01;
    aDataArray2[3] = type;
    ws.send(aDataArray2.buffer);
}

export function sendMsgCloseVideo() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x08;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
    context.clearRect(0, 0, canvas.width, canvas.height);
}

function sendMsgCloseVideoSecond() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x28;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
    contextSecond.clearRect(0, 0, canvas.width, canvas.height);
}

function sendMsgChangeResolution(camId, width, height) {
    imgOrignalW = width;
    imgOrignalH = height;
    let aDataArray = new Uint8Array(8);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x02;
    aDataArray[2] = 0x05;
    aDataArray[3] = camId;
    aDataArray[4] = width / 256;
    aDataArray[5] = width % 256;
    aDataArray[6] = height / 256;
    aDataArray[7] = height % 256;
    ws.send(aDataArray.buffer);
}

function sendMsgSetFilePath(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x1c;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelCustom(index, pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(6 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x1d;
    aDataArray[2] = len + 3;
    aDataArray[3] = index / 256;
    aDataArray[4] = index % 256;
    aDataArray[5] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[6 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelCustomSecond(index, pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(6 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x46;
    aDataArray[2] = len + 3;
    aDataArray[3] = index / 256;
    aDataArray[4] = index % 256;
    aDataArray[5] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[6 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelFixed(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x1f;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelFixedSecond(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x48;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelTime() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x1e;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelTimeSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x47;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileNameModelBarcode() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x2b;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetFileType(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x20;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgSetConntinousShotModel(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x21;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgSetConntinousShotModelTime(len) {
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x22;
    aDataArray[2] = 0x02;
    aDataArray[3] = len / 256;
    aDataArray[4] = len % 256;
    ws.send(aDataArray.buffer);
}

function sendMsgUploadFile(uploadSerHead, uploadSerLast, uploadSerFile) {
    let path = encodeURI(uploadSerHead);
    let pathdata = stringToByte(path);
    let len = path.length;

    let path2 = encodeURI(uploadSerLast);
    let pathdata2 = stringToByte(path2);
    let len2 = path2.length;

    let path3 = encodeURI(uploadSerFile);
    let pathdata3 = stringToByte(path3);
    let len3 = path3.length;

    let aDataArray = new Uint8Array(8 + len + len2 + len3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x24;
    aDataArray[2] = 5 + len + len2 + len3;
    aDataArray[3] = 0x00;
    aDataArray[4] = 80 % 256;
    aDataArray[5] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[6 + i] = pathdata[i];
    }
    aDataArray[6 + len] = len2;
    for (let i = 0; i < len2; i++) {
        aDataArray[7 + len + i] = pathdata2[i];
    }
    aDataArray[7 + len + len2] = len3;
    for (let i = 0; i < len3; i++) {
        aDataArray[8 + len + len2 + i] = pathdata3[i];
    }
    ws.send(aDataArray.buffer);

}

function sendMsgUploadFilePort(port, uploadSerHead, uploadSerLast, uploadSerFile) {
    let path = encodeURI(uploadSerHead);
    let pathdata = stringToByte(path);
    let len = path.length;

    let path2 = encodeURI(uploadSerLast);
    let pathdata2 = stringToByte(path2);
    let len2 = path2.length;

    let path3 = encodeURI(uploadSerFile);
    let pathdata3 = stringToByte(path3);
    let len3 = path3.length;

    let aDataArray = new Uint8Array(9 + len + len2 + len3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xb1;
    aDataArray[2] = 5 + len + len2 + len3;
    aDataArray[3] = port / 256;
    aDataArray[4] = port % 256;
    aDataArray[5] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[6 + i] = pathdata[i];
    }
    aDataArray[6 + len] = len2 / 256;
    aDataArray[7 + len] = len2 % 256;

    for (let i = 0; i < len2; i++) {
        aDataArray[8 + len + i] = pathdata2[i];
    }
    aDataArray[8 + len + len2] = len3;
    for (let i = 0; i < len3; i++) {
        aDataArray[9 + len + len2 + i] = pathdata3[i];
    }
    ws.send(aDataArray.buffer);

}


export function sendMsgCapture(type) {
    let str;
    if (type != 2) {
        let aDataArray = new Uint8Array(4);
        aDataArray[0] = 0xef;
        aDataArray[1] = 0x0a;
        aDataArray[2] = 0x01;
        aDataArray[3] = 0x00;
        str = ws.send(aDataArray.buffer);
    } else {
        let x1 = recX_manual;
        if (recX_manual > recX_manual + recW_manual) {
            x1 = recX_manual + recW_manual;

        }
        let y1 = recY_manual;
        if (recY_manual > recY_manual + recH_manual) {
            y1 = recY_manual + recH_manual;

        }


        //   let bpp = rec_ww/imgOrignalW;

        // if(rorateAngleType==1 || rorateAngleType==3){
        //   bpp = rec_hh/imgOrignalH;
        // }

        //let w1 = Math.abs(recW_manual/bpp);
        //  let h1 = Math.abs(recH_manual/bpp);
        let xsend = x1 - (canvas.width / 2 - rec_ww / 2);
        let ysend = y1 - (canvas.height / 2 - rec_hh / 2);


        if (xsend < 0) xsend = 0;
        if (ysend < 0) ysend = 0;
        let aDataArray = new Uint8Array(11);
        aDataArray[0] = 0xef;
        //aDataArray[1] = 0x0f;
        aDataArray[1] = 0x4b;
        aDataArray[2] = 0x08;
        aDataArray[3] = xsend / 256;
        aDataArray[4] = xsend % 256;
        aDataArray[5] = ysend / 256;
        aDataArray[6] = ysend % 256;
        aDataArray[7] = cutXCaibian / 256;
        aDataArray[8] = cutXCaibian % 256;
        aDataArray[9] = cutYCaibian / 256;
        aDataArray[10] = cutYCaibian % 256;
        // aDataArray[7] = recW_manual/256;
        // aDataArray[8] = recW_manual%256;
        // aDataArray[9] = recH_manual/256;
        // aDataArray[10] = recH_manual%256;
        str = ws.send(aDataArray.buffer);

    }
    return str;
}

function sendMsgCaptureSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x29;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgCaptureSecondCaibian() {
    let x1 = recX_manual2;
    if (recX_manual2 > recX_manual2 + recW_manual2) {
        x1 = recX_manual2 + recW_manual2;

    }
    let y1 = recY_manual2;
    if (recY_manual2 > recY_manual2 + recH_manual2) {
        y1 = recY_manual2 + recH_manual2;

    }

    let xsend = x1 - (canvasSecond.width / 2 - rec_ww2 / 2);
    let ysend = y1 - (canvasSecond.height / 2 - rec_hh2 / 2);


    if (xsend < 0) xsend = 0;
    if (ysend < 0) ysend = 0;
    let aDataArray = new Uint8Array(11);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x4c;
    aDataArray[2] = 0x08;
    aDataArray[3] = xsend / 256;
    aDataArray[4] = xsend % 256;
    aDataArray[5] = ysend / 256;
    aDataArray[6] = ysend % 256;
    aDataArray[7] = cutXCaibian2 / 256;
    aDataArray[8] = cutXCaibian2 % 256;
    aDataArray[9] = cutYCaibian2 / 256;
    aDataArray[10] = cutYCaibian2 % 256;

    ws.send(aDataArray.buffer);
}

function sendMsgShowImageSettingWindow() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x0b;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgShowImageSettingWindowB() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x45;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}


export function sendMsgZoom(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x0d;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

export function sendMsgSetCutType(type) {
    canvasX = 0;
    canvasY = 0;
    CutType = type;
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x0e;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgSetJiubianModel(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x10;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);

}

function sendMsgGetCamNum() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x16;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);

}

export function sendMsgGetResolution(camid) {
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x18;
    aDataArray[2] = 0x02;
    aDataArray[3] = 0x00;
    aDataArray[4] = camid;
    ws.send(aDataArray.buffer);
}

function sendMsgGetResolutionSecond(camid) {
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x18;
    aDataArray[2] = 0x02;
    aDataArray[3] = 0x01;
    aDataArray[4] = camid;
    ws.send(aDataArray.buffer);
}

function sednMsgSavePDF(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x11;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgAddPDF(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x12;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgSaveTIF(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa4;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgAddTIF(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa5;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgClearTIF() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa6;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgWaterMarkOpen(pathUnicode, fontSize, fontStyleIndex, r, g, b, xoffset, yoffset) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;

    let aDataArray = new Uint8Array(11 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x1a;
    aDataArray[2] = 8 + len;
    aDataArray[3] = fontSize;
    aDataArray[4] = fontStyleIndex;
    aDataArray[5] = r;
    aDataArray[6] = g;
    aDataArray[7] = b;
    aDataArray[8] = xoffset;
    aDataArray[9] = yoffset;
    aDataArray[10] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[11 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgWaterMarkOpenAlph(pathUnicode, fontSize, fontStyleIndex, r, g, b, xoffset, yoffset, alph) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;

    let aDataArray = new Uint8Array(12 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa9;
    aDataArray[2] = 9 + len;
    aDataArray[3] = fontSize;
    aDataArray[4] = fontStyleIndex;
    aDataArray[5] = r;
    aDataArray[6] = g;
    aDataArray[7] = b;
    aDataArray[8] = xoffset;
    aDataArray[9] = yoffset;
    aDataArray[10] = alph;
    aDataArray[11] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[12 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgWaterMarkClose() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x1b;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgBubaiType(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x2c;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sednMsgQuqudiseType(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x34;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgCombineTwoImage(path1Unicode, path2Unicode, path3Unicode, type) {
    let path1 = encodeURI(path1Unicode);
    let pathdata1 = stringToByte(path1);
    let len1 = path1.length;

    let path2 = encodeURI(path2Unicode);
    let pathdata2 = stringToByte(path2);
    let len2 = path2.length;

    let path3 = encodeURI(path3Unicode);
    let pathdata3 = stringToByte(path3);
    let len3 = path3.length;

    let aDataArray = new Uint8Array(7 + len1 + len2 + len3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x13;
    aDataArray[2] = len1 + len2 + len3 + 4;
    aDataArray[3] = type;
    aDataArray[4] = len1;
    for (let i = 0; i < len1; i++) {
        aDataArray[5 + i] = pathdata1[i];
    }
    aDataArray[5 + len1] = len2;
    for (let i = 0; i < len2; i++) {
        aDataArray[6 + len1 + i] = pathdata2[i];
    }

    aDataArray[6 + len1 + len2] = len3;
    for (let i = 0; i < len3; i++) {
        aDataArray[7 + len1 + len2 + i] = pathdata3[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgCombineTwoImageBase64(path1Unicode, path2Unicode, type) {
    let path1 = encodeURI(path1Unicode);
    let pathdata1 = stringToByte(path1);
    let len1 = path1.length;

    let path2 = encodeURI(path2Unicode);
    let pathdata2 = stringToByte(path2);
    let len2 = path2.length;


    let aDataArray = new Uint8Array(7 + len1 + len2);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x85;
    aDataArray[2] = len1 + len2 + 3;
    aDataArray[3] = type;
    aDataArray[4] = len1;
    for (let i = 0; i < len1; i++) {
        aDataArray[5 + i] = pathdata1[i];
    }
    aDataArray[5 + len1] = len2;
    for (let i = 0; i < len2; i++) {
        aDataArray[6 + len1 + i] = pathdata2[i];
    }


    ws.send(aDataArray.buffer);
}

function sendMsgCombineTwoImageInside(path1Unicode, path2Unicode, path3Unicode, xoff, yoff) {
    let path1 = encodeURI(path1Unicode);
    let pathdata1 = stringToByte(path1);
    let len1 = path1.length;

    let path2 = encodeURI(path2Unicode);
    let pathdata2 = stringToByte(path2);
    let len2 = path2.length;

    let path3 = encodeURI(path3Unicode);
    let pathdata3 = stringToByte(path3);
    let len3 = path3.length;

    let aDataArray = new Uint8Array(11 + len1 + len2 + len3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x86;
    aDataArray[2] = len1 + len2 + len3 + 7;
    aDataArray[3] = xoff / 256;
    aDataArray[4] = xoff % 256;
    aDataArray[5] = yoff / 256;
    aDataArray[6] = yoff % 256;
    aDataArray[7] = len1;
    for (let i = 0; i < len1; i++) {
        aDataArray[8 + i] = pathdata1[i];
    }
    aDataArray[8 + len1] = len2;
    for (let i = 0; i < len2; i++) {
        aDataArray[9 + len1 + i] = pathdata2[i];
    }

    aDataArray[9 + len1 + len2] = len3;
    for (let i = 0; i < len3; i++) {
        aDataArray[10 + len1 + len2 + i] = pathdata3[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgCombineTwoImageInsideBase64(path1Unicode, path2Unicode, xoff, yoff) {
    let path1 = encodeURI(path1Unicode);
    let pathdata1 = stringToByte(path1);
    let len1 = path1.length;

    let path2 = encodeURI(path2Unicode);
    let pathdata2 = stringToByte(path2);
    let len2 = path2.length;


    let aDataArray = new Uint8Array(10 + len1 + len2);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x87;
    aDataArray[2] = len1 + len2 + 6;
    aDataArray[3] = xoff / 256;
    aDataArray[4] = xoff % 256;
    aDataArray[5] = yoff / 256;
    aDataArray[6] = yoff % 256;
    aDataArray[7] = len1;
    for (let i = 0; i < len1; i++) {
        aDataArray[8 + i] = pathdata1[i];
    }
    aDataArray[8 + len1] = len2;
    for (let i = 0; i < len2; i++) {
        aDataArray[9 + len1 + i] = pathdata2[i];
    }

    ws.send(aDataArray.buffer);
}

function sendMsgSetAutoExposure(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x2d;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgGetExposureRange() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x31;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgGetBrightnessRange() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x2e;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetBrightness(temp) {
    let type;
    if (temp < 0) {
        type = 0;
    } else {
        type = 1;
    }
    temp = Math.abs(temp);
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x2f;
    aDataArray[2] = 0x02;
    aDataArray[3] = type;
    aDataArray[4] = temp;
    ws.send(aDataArray.buffer);
}

function sendMsgSetExposure(temp) {
    let type;
    if (temp < 0) {
        type = 0;
    } else {
        type = 1;
    }
    temp = Math.abs(temp);
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x33;
    aDataArray[2] = 0x02;
    aDataArray[3] = type;
    aDataArray[4] = temp;
    ws.send(aDataArray.buffer);
}

function sednMsgGetBase64(filename) {
    let path = encodeURI(filename);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x35;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgDeleteFile(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x38;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgQrcode(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x39;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgBarcode(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x44;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

export function sendMsgGetMainCameraID() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x3a;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x01;
    ws.send(aDataArray.buffer);
}

function sendMsgStartIDCard() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x3c;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgGetOneIC() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x3c;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x01;
    ws.send(aDataArray.buffer);
}

function sendMsgGetICValues(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x3d;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

export function sendMsgRotateL() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x40;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0;
    ws.send(aDataArray.buffer);
}

export function sendMsgRotateR() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x40;
    aDataArray[2] = 0x01;
    aDataArray[3] = 1;
    ws.send(aDataArray.buffer);
}

export function sendMsgBestSize() {
    canvasX = 0;
    canvasY = 0;
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x0d;
    aDataArray[2] = 0x01;
    aDataArray[3] = 2;
    ws.send(aDataArray.buffer);
}

export function sendMsgTrueSize() {
    canvasX = 0;
    canvasY = 0;
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x0d;
    aDataArray[2] = 0x01;
    aDataArray[3] = 3;
    ws.send(aDataArray.buffer);
}


function sendMsgWorkIDCard() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x41;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x01;
    ws.send(aDataArray.buffer);
}

function sendMsgStopWorkIDCard() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x41;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x00;
    ws.send(aDataArray.buffer);
}

export function sendMsgShotBase64(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x42;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgSetJpgQuanlity(value) {
    let aDataArray2 = new Uint8Array(4);
    aDataArray2[0] = 0xef;
    aDataArray2[1] = 0x49;
    aDataArray2[2] = 0x01;
    aDataArray2[3] = value;
    ws.send(aDataArray2.buffer);
}

function sendMsgGetICPictureAll() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x4d;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgInitFinger() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x4f;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgStartFinger() {

    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x50;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x01;
    ws.send(aDataArray.buffer);
}

function sendMsgCloseFinger() {

    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x50;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgBeginVideo(pathUnicode, id, frame) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(6 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x51;
    aDataArray[2] = len + 3;
    aDataArray[3] = id;
    aDataArray[4] = frame;
    aDataArray[5] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[6 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

export function sendMsgStopVideo() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x52;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgBeginVideoSecond(pathUnicode, id, frame) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(6 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x53;
    aDataArray[2] = len + 3;
    aDataArray[3] = id;
    aDataArray[4] = frame;
    aDataArray[5] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[6 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgStopVideoSecond() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x54;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgGetAudioName() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x55;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgBarQrcode(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x59;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgMakeDir(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x5a;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgAutoFoucs() {

    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x5b;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
    context.clearRect(0, 0, canvas.width, canvas.height);
}

function sednMsgFaceCheckInit() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x5c;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgFaceCheckUninit() {
    isFaceOpen = false;
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x5d;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgStartFaceCheck() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x5e;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgStopFaceCheck() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x61;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgFaceCheckInitSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x63;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgFaceCheckUninitSecond() {
    isFaceOpenSecond = false;
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x64;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgStartFaceCheckSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x65;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgStopFaceCheckSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x66;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgBankCardFun(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x6b;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgInitFingerFunOrCloase(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x6c;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sendMsgRegisterFinger() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x6d;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgStopRegisterFinger() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x6e;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgVerifyFinger(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x6f;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sednMsgStopVerifyFinger() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x70;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sednMsgQFaceStratDoubleOrClose(type) {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x74;
    aDataArray[2] = 0x01;
    aDataArray[3] = type;
    ws.send(aDataArray.buffer);
}

function sednMsgFaceCheckInitDouble() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x75;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetDpi(x, y) {
    let aDataArray = new Uint8Array(7);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x76;
    aDataArray[2] = 0x04;
    aDataArray[3] = x / 256;
    aDataArray[4] = x % 256;
    aDataArray[5] = y / 256;
    aDataArray[6] = y % 256;
    ws.send(aDataArray.buffer);
}

function sednMsgReleaseAll() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x77;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgFaceCheck(type) {
    if (type == 0) {
        isFaceOpen = false;
    }
    let aDataArray2 = new Uint8Array(4);
    aDataArray2[0] = 0xef;
    aDataArray2[1] = 0x78;
    aDataArray2[2] = 0x01;
    aDataArray2[3] = type;
    ws.send(aDataArray2.buffer);
}

function sendMsgCaptureFace() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x79;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgFaceCheckSecond(type) {
    if (type == 0) {
        isFaceOpenSecond = false;
    }
    let aDataArray2 = new Uint8Array(4);
    aDataArray2[0] = 0xef;
    aDataArray2[1] = 0x7a;
    aDataArray2[2] = 0x01;
    aDataArray2[3] = type;
    ws.send(aDataArray2.buffer);
}

function sendMsgCaptureFaceSecond() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x7b;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgGetFinger(type) {
    let aDataArray2 = new Uint8Array(4);
    aDataArray2[0] = 0xef;
    aDataArray2[1] = 0x7f;
    aDataArray2[2] = 0x01;
    aDataArray2[3] = type;
    ws.send(aDataArray2.buffer);
}

function sendMsgVerifyFingerBase64(datalen, pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(7 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x81;
    aDataArray[2] = 0x00;
    aDataArray[3] = datalen / 256;
    aDataArray[4] = datalen % 256;
    aDataArray[5] = len / 256;
    aDataArray[6] = len % 256;
    for (let i = 0; i < len; i++) {
        aDataArray[7 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgAddFingerBase64(datalen, pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(7 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x94;
    aDataArray[2] = 0x00;
    aDataArray[3] = datalen / 256;
    aDataArray[4] = datalen % 256;
    aDataArray[5] = len / 256;
    aDataArray[6] = len % 256;
    for (let i = 0; i < len; i++) {
        aDataArray[7 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgClearAllFingerBase64() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x95;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}


function sendMsgVerifyFingerAllBase64() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x96;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgCheckCamDev() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x89;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetFoucs(value) {
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x8c;
    aDataArray[2] = 0x02;
    aDataArray[3] = value / 256;
    aDataArray[4] = value % 256;
    ws.send(aDataArray.buffer);
}

function sendMsgSetDebugModel() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa3;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgGetALLVidPid() {
    let aDataArray = new Uint8Array(3);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa7;
    aDataArray[2] = 0x00;
    ws.send(aDataArray.buffer);
}

function sendMsgSetFaceCheckImg(pathUnicode) {
    let path = encodeURI(pathUnicode);
    let pathdata = stringToByte(path);
    let len = path.length;
    let aDataArray = new Uint8Array(3 + len);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xa8;
    aDataArray[2] = len;
    for (let i = 0; i < len; i++) {
        aDataArray[3 + i] = pathdata[i];
    }
    ws.send(aDataArray.buffer);
}

function sendMsgCAM_ProSetMain(type, value) {
    let aDataArray = new Uint8Array(6);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xaa;
    aDataArray[2] = 0x03;
    aDataArray[3] = type;
    aDataArray[4] = value / 256;
    aDataArray[5] = value % 256;
    ws.send(aDataArray.buffer);
}

function sendSendStrBase64() {
    let aDataArray = new Uint8Array(4);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0xb2;
    aDataArray[2] = 0x01;
    aDataArray[3] = 0x01;
    ws.send(aDataArray.buffer);
}

function sednMsgControlLed(camid, type) {
    let aDataArray = new Uint8Array(5);
    aDataArray[0] = 0xef;
    aDataArray[1] = 0x88;
    aDataArray[2] = 0x02;
    aDataArray[3] = camid;
    aDataArray[4] = type;
    ws.send(aDataArray.buffer);
}


function GetFaceZuobiao(Xdis, Ydis) {
    if (isFaceOpen) {
        for (let j = 0; j < faceNum; j++) {
            for (let i = 0; i < 3; i++) {

                context.moveTo(faceZuobiao[2 * i + j * 8] + Xdis, faceZuobiao[2 * i + j * 8 + 1] + Ydis);
                context.lineTo(faceZuobiao[2 * i + j * 8 + 2] + Xdis, faceZuobiao[2 * i + j * 8 + 3] + Ydis);
                context.stroke();
            }

            context.moveTo(faceZuobiao[6 * i + j * 8] + Xdis, faceZuobiao[6 * i + j * 8 + 1] + Ydis);
            context.lineTo(faceZuobiao[0 + j * 8] + Xdis, faceZuobiao[1 + j * 8] + Ydis);
            context.stroke();
        }
    }
}

function GetFaceZuobiaoSecond(Xdis, Ydis) {
    if (isFaceOpenSecond) {
        contextSecond.beginPath();
        contextSecond.strokeStyle = "rgb(0,255,0)";
        contextSecond.lineWidth = 2;
        for (let j = 0; j < faceNumSecond; j++) {
            for (let i = 0; i < 3; i++) {

                contextSecond.moveTo(faceZuobiaoSecond[2 * i + j * 8] + Xdis, faceZuobiaoSecond[2 * i + j * 8 + 1] + Ydis);
                contextSecond.lineTo(faceZuobiaoSecond[2 * i + j * 8 + 2] + Xdis, faceZuobiaoSecond[2 * i + j * 8 + 3] + Ydis);
                contextSecond.stroke();
            }

            contextSecond.moveTo(faceZuobiaoSecond[6 * i + j * 8] + Xdis, faceZuobiaoSecond[6 * i + j * 8 + 1] + Ydis);
            contextSecond.lineTo(faceZuobiaoSecond[0 + j * 8] + Xdis, faceZuobiaoSecond[1 + j * 8] + Ydis);
            contextSecond.stroke();
        }
    }
}


function SetCusCutFirst() {


    if (setCusCut1) {
        setCusCut1 = false;
        let bpp = rec_ww / imgOrignalW;
        if (rorateAngleType == 1 || rorateAngleType == 3) {
            bpp = rec_ww / imgOrignalH;
        }
        recX_manual = cusCutX1 * bpp + (canvas.width / 2 - rec_ww / 2);
        recY_manual = cusCutY1 * bpp + (canvas.height / 2 - rec_hh / 2);
        recW_manual = cusCutW1 * bpp;
        recH_manual = cusCutH1 * bpp;
        cutXCaibian = cusCutW1;
        cutYCaibian = cusCutH1;
    }


}

function SetCusCutSec() {


    if (setCusCut2) {
        setCusCut2 = false;
        let bpp = rec_ww2 / imgOrignalW2;
        recX_manual2 = cusCutX2 * bpp + (canvasSecond.width / 2 - rec_ww2 / 2);
        recY_manual2 = cusCutY2 * bpp + (canvasSecond.height / 2 - rec_hh2 / 2);
        recW_manual2 = cusCutW2 * bpp;
        recH_manual2 = cusCutH2 * bpp;
        cutXCaibian2 = cusCutW2;
        cutYCaibian2 = cusCutH2;

    }


}


function SetCusCropPlaceWs(cutX, cutY, cutW, cutH) {

    setCusCut1 = true;
    cusCutX1 = cutX;
    cusCutY1 = cutY;
    cusCutW1 = cutW;
    cusCutH1 = cutH;

    //  let bpp = rec_ww/imgOrignalW;
    //  if(rorateAngleType==1 || rorateAngleType==3){
    //   bpp = rec_ww/imgOrignalH;
    // }
    // recX_manual = cutX*bpp+ (canvas.width/2-rec_ww/2);
    // recY_manual = cutY*bpp +(canvas.height/2-rec_hh/2);
    // recW_manual = cutW*bpp;
    // recH_manual = cutH*bpp;
    // cutXCaibian = cutW;
    // cutYCaibian = cutH;


}

function SetCusCropPlaceWs2(cutX, cutY, cutW, cutH) {

    setCusCut2 = true;
    cusCutX2 = cutX;
    cusCutY2 = cutY;
    cusCutW2 = cutW;
    cusCutH2 = cutH;

    // let bpp = rec_ww2/imgOrignalW2;
    // recX_manual2 = cutX*bpp+ (canvasSecond.width/2-rec_ww2/2);
    // recY_manual2 = cutY*bpp +(canvasSecond.height/2-rec_hh2/2);
    // recW_manual2 = cutW*bpp;
    // recH_manual2 = cutH*bpp;
    // cutXCaibian2 = cutW;
    // cutYCaibian2 = cutH;


}


//手动裁边时的长方形
function refreshRect() {
    context.beginPath();
    context.rect(recX_manual, recY_manual, recW_manual, recH_manual);
    context.lineWidth = 2;
    context.strokeStyle = "#0000ff";
    context.stroke();
}

function refreshRect2() {
    contextSecond.beginPath();
    contextSecond.rect(recX_manual2, recY_manual2, recW_manual2, recH_manual2);
    contextSecond.lineWidth = 2;
    contextSecond.strokeStyle = "#0000ff";
    contextSecond.stroke();
}

function stringToByte(str) {
    let bytes = new Array();
    let len, c;
    len = str.length;
    for (let i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if (c >= 0x010000 && c <= 0x10FFFF) {
            bytes.push(((c >> 18) & 0x07) | 0xF0);
            bytes.push(((c >> 12) & 0x3F) | 0x80);
            bytes.push(((c >> 6) & 0x3F) | 0x80);
            bytes.push((c & 0x3F) | 0x80);
        } else if (c >= 0x000800 && c <= 0x00FFFF) {
            bytes.push(((c >> 12) & 0x0F) | 0xE0);
            bytes.push(((c >> 6) & 0x3F) | 0x80);
            bytes.push((c & 0x3F) | 0x80);
        } else if (c >= 0x000080 && c <= 0x0007FF) {
            bytes.push(((c >> 6) & 0x1F) | 0xC0);
            bytes.push((c & 0x3F) | 0x80);
        } else {
            bytes.push(c & 0xFF);
        }
    }
    return bytes;
}

function byteToString(arr) {
    if (typeof arr === 'string') {
        return arr;
    }
    let str = '',
        _arr = arr;
    for (let i = 0; i < _arr.length; i++) {
        let one = _arr[i].toString(2),
            v = one.match(/^1+?(?=0)/);
        if (v && one.length == 8) {
            let bytesLength = v[0].length;
            let store = _arr[i].toString(2).slice(7 - bytesLength);
            for (let st = 1; st < bytesLength; st++) {
                store += _arr[st + i].toString(2).slice(2);
            }
            str += String.fromCharCode(parseInt(store, 2));
            i += bytesLength - 1;
        } else {
            str += String.fromCharCode(_arr[i]);
        }
    }
    return str;
}

function base64Encode(input) {
    let rv;
    rv = encodeURIComponent(input);
    rv = unescape(rv);
    rv = window.btoa(rv);
    return rv;
}

function isIE() { //ie?
    if (!!window.ActiveXObject || "ActiveXObject" in window)
        return true;
    else
        return false;
}

function InfoCallback(op) {
    let text = "";
    if (op == 0) {
        text = "连接成功\r\n";
    } else if (op == 0x01) {
        text = "断开成功\r\n";
    } else if (op == 0x02) {
        text = "设备已经连接\r\n";
    } else if (op == 0x03) {
        text = "设备已经关闭\r\n";
    } else if (op == 0x04) {
        text = "拍照成功\r\n";
    } else if (op == 0x05) {
        text = "pdf添加文件成功\r\n";
    } else if (op == 0x06) {
        text = "pdf保存成功\r\n";
    } else if (op == 0x07) {
        text = "图片合并成功\r\n";
    } else if (op == 0x08) {
        text = "智能连拍启动\r\n";
    } else if (op == 0x09) {
        text = "定时连拍启动\r\n";
    } else if (op == 0x10) {
        text = "定时连拍成功\r\n";
    } else if (op == 0x11) {
        text = "定时连拍关闭\r\n";
    } else if (op == 0x12) {
        text = "文件上传服务器成功\r\n";
    } else if (op == 0x13) {
        text = "水印开启\r\n";
    } else if (op == 0x14) {
        text = "水印关闭\r\n";
    } else if (op == 0x15) {
        text = "此设备属于本公司\r\n";
    } else if (op == 0x16) {
        text = "此设备不属于本公司\r\n";
    } else if (op == 0x17) {
        text = "自动曝光启动\r\n";
    } else if (op == 0x18) {
        text = "自动曝光关闭\r\n";
    } else if (op == 0x19) {
        text = "身份证功能启动成功\r\n";
    } else if (op == 0x1a) {
        text = "身份证功能启动失败\r\n";
    } else if (op == 0x1b) {
        text = "身份证读卡成功\r\n";
    } else if (op == 0x1c) {
        text = "身份证读卡失败\r\n";
    } else if (op == 0x1d) {
        text = "重新操作\r\n";
    } else if (op == 0x1e) {
        text = "未发现模块\r\n";
    } else if (op == 0x1f) {
        text = "未启动身份证功能\r\n";
    } else if (op == 0x20) {
        text = "启动身份证自动读卡\r\n";
    } else if (op == 0x21) {
        text = "关闭身份证自动读卡\r\n";
    } else if (op == 0x22) {
        text = "启动拍照只生成base64\r\n";
    } else if (op == 0x23) {
        text = "关闭拍照只生成base64\r\n";
    } else if (op == 0x25) {
        text = "初始化指纹模块成功\r\n";
    } else if (op == 0x26) {
        text = "初始化指纹模块失败\r\n";
    } else if (op == 0x27) {
        text = "未初始化指纹模块\r\n";
    } else if (op == 0x28) {
        text = "身份证没有指纹数据\r\n";
    } else if (op == 0x29) {
        text = "指纹认证成功\r\n";
    } else if (op == 0x30) {
        text = "开始指纹认证\r\n";
    } else if (op == 0x31) {
        text = "正在指纹认证\r\n";
    } else if (op == 0x32) {
        text = "停止指纹认证\r\n";
    } else if (op == 0x33) {
        text = "指纹认证失败\r\n";
    } else if (op == 0x34) {
        text = "开始录像\r\n";
    } else if (op == 0x35) {
        text = "停止录像\r\n";
    } else if (op == 0x36) {
        text = "正在录像中\r\n";
    } else if (op == 0x37) {
        text = "开始录像副头\r\n";
    } else if (op == 0x38) {
        text = "停止录像副头\r\n";
    } else if (op == 0x39) {
        text = "正在录像中副头\r\n";
    } else if (op == 0x44) {
        text = "建立文件成功\r\n";
    } else if (op == 0x45) {
        text = "建立文件失败\r\n";
    } else if (op == 0x46) {
        text = "人脸识别初始化成功\r\n";
    } else if (op == 0x47) {
        text = "启动人脸对比\r\n";
    } else if (op == 0x48) {
        text = "人脸识别初始化成功\r\n";
    } else if (op == 0x49) {
        text = "主头正在连接中\r\n";
    } else if (op == 0x4a) {
        text = "主头等待连接\r\n";
    } else if (op == 0x4b) {
        text = "副头正在连接中\r\n";
    } else if (op == 0x4c) {
        text = "副头等待连接\r\n";
    } else if (op == 0xa0) {
        text = "没有对应分辨率\r\n";
    } else if (op == 0xa1) {
        text = "pdf没有添加任何文件\r\n";
    } else if (op == 0xa2) {
        text = "文件不存在\r\n";
    } else if (op == 0xa3) {
        text = "意外断开\r\n";
    } else if (op == 0xa4) {
        text = "连接不上\r\n";
    } else if (op == 0xa5) {
        text = "pdf添加文件不是jpg格式\r\n";
    } else if (op == 0xa6) {
        text = "没有发现摄像头\r\n";
    } else if (op == 0xa7) {
        text = "camid无效\r\n";
    } else if (op == 0xa8) {
        text = "图片尺寸太小\r\n";
    } else if (op == 0xa9) {
        text = "文件上传服务器失败\r\n";
    } else if (op == 0xaa) {
        text = "该设备没有副头\r\n";
    } else if (op == 0xab) {
        text = "条码识别失败\r\n";
    } else if (op == 0xac) {
        text = "二维码识别失败\r\n";
    } else if (op == 0xad) {
        text = "图片合并失败\r\n";
    } else if (op == 0xae) {
        text = "设置路径失败,路径不存在\r\n";
    } else if (op == 0xaf) {
        text = "摄像头切换太频繁\r\n";
    } else if (op == 0xb1) {
        text = "未发现指纹模块\r\n";
    } else if (op == 0xb2) {
        text = "录像分辨率不能高于1600*1200\r\n";
    } else if (op == 0xb3) {
        text = "副头录像分辨率不能高于1600*1200\r\n";
    } else if (op == 0xb4) {
        text = "没发现麦克风\r\n";
    } else if (op == 0xb8) {
        text = "人脸识别初始化失败\r\n";
    } else if (op == 0xb9) {
        text = "请读取身份证信息\r\n";
    } else if (op == 0xba) {
        text = "请先初始化人脸识别\r\n";
    } else if (op == 0xbb) {
        text = "没有发现合适的人脸\r\n";
    }
    EventBus.$emit("camera.info", text)
}

//必需重写---获取分辨率(data为分辨率数组,每2个为一组,宽高)
function GetDeviceResolution(data) {
    let resolution = new Array(data.length / 2);
    if (data.length > 0) {
        for (let i = 0; i < data.length / 2; i++) {
            resolution[i] = [data[i * 2], data[i * 2 + 1]]
        }
        EventBus.$emit("camera.resolution", resolution)
    }
}

//设备1初始化完成,可以进行相关操作
function LoadOver() {
    EventBus.$emit("camera.loadOver", ws)
}

export function StartCam(CamID, width, height) {
    sendMsgRefreshCam();
    sendMsgStartVideo(CamID, width, height);
}

//必需重写---获取设备名称(num为当前摄像头数量,strUsbNamr为摄像头名字数组)
function GetDevName(num, strUsbNamr) {
    EventBus.$emit("camera.devNames", strUsbNamr)
    if (num > 0) {
        if (isSecondDev) {
            var obj2 = document.getElementById("DeviceName2");
            obj2.options.length = 0;
            if (num > 1) {
                for (var i = 0; i < num; i++) {
                    var objOption = document.createElement("option");
                    objOption.text = strUsbNamr[i];
                    objOption.value = i;
                    obj2.options.add(objOption);
                }
                obj2.options[camidSub].selected = true;
                OcxGetDeviceResolutionSecond();
            }
        }
    }

}

//拍照
export function CaptureImage_web(type, pfId) {
    // if(isIE){
    //   axCam_Ocx.CaptureImage();
    // }else {
    //   sendMsgCapture(type);
    // }
    personFileId = pfId;
    sendMsgCapture(type);
    return imageData;

}

//设置拍照时是否只返回base64
export function funSetImagebase64() {
    // var isCheck = document.getElementById("checkboxBase").checked;
    // if(isCheck){
    //   SetImagebase64(1);
    // }else {
    //   SetImagebase64(0);
    // }
    SetImagebase64(1);
}

function SetImagebase64(type) {
    // if(isIE){
    //   axCam_Ocx.IsImageBase64(type);
    //   if(isSecondDev){
    //     axCam_Ocx2.IsImageBase64(type);
    //   }
    // }else {
    //   sendMsgShotBase64(type);
    // }
    console.log("设备base64拍照--------2")
    sendMsgShotBase64(type);
}

// 将base64字符串转换为Blob对象
function dataURLtoBlob(dataurl) {
    const arr = dataurl.split(',');
    const mime = arr[0].match(/:(.*?);/)[1];
    const bstr = atob(arr[1]);
    let n = bstr.length;
    const u8arr = new Uint8Array(n);

    while (n--) {
        u8arr[n] = bstr.charCodeAt(n);
    }

    return new Blob([u8arr], {type: mime});
}

function InfoTextCallback(type, str) {

    let text = "";
    if (type == 0) {
        text = "图片路径:" + str + "\r\n";
    } else if (type == 1) {
        text = "默认路径:    " + str + "\r\n";

    } else if (type == 2) {
        text = "条码:    " + str + "\r\n";

    } else if (type == 3) {
        text = "文件上传服务器成功:" + str + "\r\n";

    } else if (type == 4) {
        text = "文件上传服务器失败:" + str + "\r\n";

    } else if (type == 5) {
        debugger
        text = "base64编码成功,请自行处理str\r\n";
        let base64Data = "data:;base64," + str;
        // 创建Blob对象
        const blob = dataURLtoBlob(base64Data);

        // 创建FormData对象
        const formData = new FormData();
        formData.append('file', blob, new Date().getTime() + '_image.jpg');
        formData.append("personFileId", personFileId);

        axios.post(process.env.VUE_APP_BASE_API + "/business/fileAttachment/upload", formData, {
            headers: {
                'Content-Type': 'multipart/form-data',
                Authorization: "Bearer " + getToken()
            }
        }).then(response => {
            // 处理响应数据
            console.log(response.data);
            EventBus.$emit('externalEvent', response.data);
        }).catch(error => {
            // 处理错误情况
            console.error(error);
        });
    } else if (type == 6) {
        text = "删除文件成功:" + str + "\r\n";
    } else if (type == 7) {
        text = "二维码:" + str + "\r\n";
    } else if (type == 8) {
        text = "拍照失败:" + str + "\r\n";
    } else if (type == 9) {
        text = "身份证名字:" + str + "\r\n";
    } else if (type == 10) {
        text = "身份证号码:" + str + "\r\n";
    } else if (type == 11) {
        text = "身份证性别:" + str + "\r\n";
    } else if (type == 12) {
        text = "身份证民族:" + str + "\r\n";
    } else if (type == 13) {
        text = "身份证生日:" + str + "\r\n";
    } else if (type == 14) {
        text = "身份证地址:" + str + "\r\n";
    } else if (type == 15) {
        text = "身份证签发机关:" + str + "\r\n";
    } else if (type == 16) {
        text = "身份证有效开始日期:" + str + "\r\n";
    } else if (type == 17) {
        text = "身份证有效截至日期:" + str + "\r\n";
    } else if (type == 18) {
        text = "安全模块号:" + str + "\r\n";
    } else if (type == 19) {
        //身份证头像
        text = "身份证头像base64\r\n";
        // var imgobj1 = document.getElementById("img1");
        // imgobj1.src = "data:;base64," + str;
    } else if (type == 21) {
        text = "base64编码成功,请自行处理str(副头)\r\n";
        //text ="data:;base64," +str+"\r\n";
        // var imgobj1 = document.getElementById("img2");
        // imgobj1.src = "data:;base64," + str;
    } else if (type == 22) {
        text = "曝光范围:" + str + "\r\n";
    } else if (type == 23) {
        text = "亮度范围:" + str + "\r\n";
    } else if (type == 24) {
        text = "上传服务器返回:" + str + "\r\n";
    } else if (type == 25) {
        var imgobj1 = document.getElementById("img1");
        // imgobj1.src = "data:;base64," + str;
        // text = "身份证复印件"+"\r\n";
    } else if (type == 26) {
        text = "当前设备数量:" + str + "\r\n";
    } else if (type == 27) {
        text = "麦克风:" + str + "\r\n";
    } else if (type == 28) {
        text = "人脸抓拍base64编码成功,请自行处理str\r\n";
    }

    return "data:;base64," + str;
}
